package edu.tsinghua.mrpvc.device.camera;

import java.util.Dictionary;
import java.util.Hashtable;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;

import edu.tsinghua.mrpvc.device.CameraDevice;
//import edu.tsinghua.mrpvc.simulate.util.SimulateTopic;

public class Activator implements BundleActivator, EventHandler {

//	private CameraDeviceImpl camera;
//	private final static String[] RESPONSE_TOPICS = {CameraDevice.EVENT_TOPIC_ISVALID};
	//private final static String[] SIMULATE_TOPICS = {SimulateTopic.CAMERA_CTRL_TV, SimulateTopic.CAMERA_CTRL_CURTAIN}; 
	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
//		camera = new CameraDeviceImpl(context, "1");
//		context.registerService(CameraDevice.class.getName(), camera, null);
//		
//		Dictionary<String, Object> resProperty = new Hashtable<String, Object>();
//		resProperty.put(EventConstants.EVENT_TOPIC, RESPONSE_TOPICS);
//		context.registerService(EventHandler.class.getName(), camera, resProperty);
		
		//Dictionary<String, Object> simProperty = new Hashtable<String, Object>();
		//simProperty.put(EventConstants.EVENT_TOPIC, SIMULATE_TOPICS);
		//context.registerService(EventHandler.class.getName(), this, simProperty);		
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
	}

	@Override
	public void handleEvent(Event event) {
		// TODO Auto-generated method stub
		//if(event.getTopic().equals(SimulateTopic.CAMERA_CTRL_CURTAIN) && 
		//		event.getProperty(CameraDevice.EVENT_PROPER_DIRECTION) != null){
		//	String direction = event.getProperty(CameraDevice.EVENT_PROPER_DIRECTION).toString();
		//	camera.setDirectionOfCurtain(direction);
		//}
		//else if(event.getTopic().equals(SimulateTopic.CAMERA_CTRL_TV) &&
		//		event.getProperty(CameraDevice.EVENT_PROPER_ACTION) != null){
		//	String action = event.getProperty(CameraDevice.EVENT_PROPER_ACTION).toString();
		//	camera.setActionOfTv(action);
		//}		
	}
}
